package org.wj.client

import java.util.concurrent.TimeUnit

import akka.actor.ActorSystem
import akka.pattern.Patterns
import akka.util.Timeout
import org.wj.message.{GetRequest, SetRequest}

class Client(remoteAddress: String) {

  private implicit val timeout: Timeout = Timeout(2, TimeUnit.SECONDS)

  private implicit val system:ActorSystem = ActorSystem("LocalSystem")

  private val remoteDb = system.actorSelection(s"akka.tcp://akka@192.168.75.1:25520/memory-db")

  def set(key:String, value: Object): Unit ={
    remoteDb ! SetRequest(key, value)
  }

  def get(key:String): Object = {
    val future = Patterns.ask(remoteDb, GetRequest(key), 100)
    future.value.get
  }
}
